home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
reader_requests
/
scilab
/
demos
/
ode
/
ode.dem
< prev
Wrap
Text File
|
1999-09-16
|
3KB
|
102 lines
mode(5)
//1- Simple Example
xbasc();
deff('[xd]=lin(t,x,a)','xd=a*x')
a=[1 1;0 2];
ea=ode(eye(2,2),0,1,list(lin,a)),exp(a)
t=0:0.1:3;
ee=ode(1,0,t,list(lin,1));plot2d1("onn",t',ee',-(1:2),"121",'x1@x2');
xtitle('dx=a*x','t',' ')
halt();xbasc();
//2- chemical process (stiff)
mode(-1)
titlepage(['Integration of ODE:';...
'dy1/dt=-0.04*y1 + 1d4*y2*y3';...
'dy3/dt= 3d7*y2*y2';...
'dy2/dt= -dy1/dt - dy3/dt';...
'finding points such that';...
'y1=1.e-4 or y3=1.e-2'])
rect=[1.d-5,-0.1,1d11,1.1];
deff('[yd]=chem(t,y)',[
'yd(1)=-0.04*y(1) + 1d4*y(2)*y(3);';
'yd(3)= 3d7*y(2)*y(2);';
'yd(2)= -yd(1) - yd(3);'])
comp(chem)
mode(1)
t=[1.d-5:0.02:.4 0.41:.1:4 40 400 4000 40000 4d5 4d6 4d7 4d8 4d9 4d10];
rtol=1.d-4;atol=[1.d-6;1.d-10;1.d-6];
y=ode([1;0;0],0,t,rtol,atol,chem);
halt();xbasc();
plot2d1("oln",t',(diag([1 10000 1])*y)',-(1:3),"111",' y1@10000 y2@y3',rect)
halt();
nt=prod(size(t));
deff('[y]=surf(t,x)','y=[x(1)-1.e-4;x(3)-1.e-2]')
comp(surf)
[y,rd,w,iw]=ode('root',[1;0;0],0,t,rtol,atol,chem,2,surf);rd
while rd<>[] then ..
[nw,ny]=size(y);
k=find(rd(1)>t(1:nt-1)&rd(1)<t(2:nt));..
write(%io(2),[rd(1);y(:,ny)]','(''t='',e10.3,'' y='',3(e10.3,'',''))')
plot2d1("oln",rd(1)',(diag([1 10000 1])*y(:,ny))',[3,3,3],"000");
//mplot([rd(1);rd(1);rd(1)],diag([1 10000 1])*y(:,ny));..
[y,rd,w,iw]=ode('root',[1;0;0],rd(1),t(k+1:nt),rtol,atol,chem,2,surf,w,iw);..
end
halt();xbasc();
//implicit
mode(-1)
//
titlepage(['Implicit ODE:';...
' ';...
'dy1/dt=-0.04*y1 + 1d4*y2*y3';...
'dy2/dt=0.04*y1 - 1d4*y2*y3-3d7*y2*y2';...
' 1 = y1+y2+y3'])
deff('[r]=chemres(t,y,yd)',[
'r(1)=-0.04*y(1)+1d4*y(2)*y(3)-yd(1);';
'r(2)=0.04*y(1)-1d4*y(2)*y(3)-3d7*y(2)*y(2)-yd(2);'
'r(3)=y(1)+y(2)+y(3)-1;'])
deff('[p]=chemad(t,y,p)','p=p+diag([1 1 0])')
deff('[p]=chemjac(t,y,yd)',['p=[-0.04, 1.d4*y(3) ,1.d4*y(2);';
' 0.04,-1d4*y(3)-6d7*y(2),-1d4*y(2);';
' 1 , 1, 1 ]'])
write(6,' macro g(t,y)-a(t,y)*ydot')
write(6,[' ';' macro x=a(t,y)+p'])
write(6,[' ';'jacobian'])
comp(chemres);comp(chemad);comp(chemjac)
mode(1)
y0=[1;0;0];
yd0=[-0.04;0.04;0];
t=[1.d-5:0.02:.4 0.41:.1:4 40 400 4000 40000 4d5 4d6 4d7 4d8 4d9 4d10];
rtol = 1d-4;atol=[1.d-6;1.d-10;1.d-6];
y=impl(y0,yd0,0,t,rtol,atol,chemres,chemad,chemjac);
halt();xbasc();
plot2d1("oln",t',(diag([1 10000 1])*y)',-(1:3),"111",'y1@10000 y2@y3',rect)
mode(-1)
halt();xbasc();
titlepage('lorenz ode ');
deff('[ydot]=lorenz(t,y)',...
"x=y(1);...
a=[-10,10,0;28,-1,-x;0,x,-8/3];...
ydot=a*y")
deff('[j]=jacobian(t,y)',...
"x=y(1);yy=y(2);z=y(3);...
j=[-10,10,0;28-z,-1,-x;-yy,x,-8/3]")
comp(lorenz);comp(jacobian);
y0=[-3;-6;12];t0=0;step=0.01;t1=10;
instants=t0:step:t1;
y=ode(y0,t0,instants,lorenz,jacobian);
xbasc(0);param3d(y(1,:),y(2,:),y(3,:))